// JavaScript Document
/** 窗口控制 **/
function forward(url) {
	window.location = url;
}

function topForward(url) {
	top.location = url;
}

function openWin(URLStr,name,width,height) {
	if(width=="" || width==null || width==undefined)
		width = 770;
	if(height=="" || height==null || height==undefined)
		height = 560;
	if(name==undefined)
		name = "";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2-30;
	var value = window.open(URLStr, name, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top);
	return value;
}

function openModalDialogWin(url,name,wid,hei){
	if(wid=="" || wid==null || wid==undefined)
		wid = 600;
	if(hei=="" || hei==null || hei==undefined)
		hei = 400;
	var value = showModalDialog(url,window,'dialogWidth='+wid+'px;dialogHeight='+hei+'px;center=yes;help=no;scroll=auto;status=no');
	return value;
}

function closeWin(backurl) {
	var parentWin = window.opener;
	if(parentWin!=null || parentWin!=undefined) {
		if(backurl != null)
			parentWin.location = backurl;
		else
			parentWin.location.reload();
	}
	self.close();
}

function openerReload() {
	window.opener.location.reload();
}

function openerTopReload(url) {
	if(url != null)
		window.opener.top.location = url;
	else
		window.opener.top.location.reload();
}

/** 通用方法 **/
function $get(id) {
	return document.getElementById(id);
}

function $getValue(id) {
	var e = document.getElementById(id);
	if(e)
		return e.value;
	else
		return null;
}

String.prototype.trim = function() {
	var re = /(^\s*)|(\s*$)/g;
	return this.replace(re,"");
}

Function.prototype.bind = function() {
  var __method = this;
  var args = [];
  if(arguments) {
  	for (var i = 0, length = arguments.length; i < length; i++)
      args.push(arguments[i]);
  }
  var object = args.shift();
  return function() {
    return __method.apply(object, args);
  }
}

/*** StringBuffer ***/
function StringBuffer() {
	this._strings = new Array();
}
StringBuffer.prototype.append = function(str) {
	this._strings.push(str);
}
StringBuffer.prototype.toString = function() {
	return this._strings.join("");
}

/*** map ***/
function Map(){
	this.container = new Object();
}
Map.prototype.put = function(key, value){
	this.container[key] = value;
}
Map.prototype.get = function(key){
	return this.container[key];
}
Map.prototype.keySet = function() {
	var keyset = new Array();
	var count = 0;
	for (var key in this.container) {
		// 跳过object的extend函数
		if (key == 'extend')
			continue;
			
		keyset[count] = key;
		count++;
	}	
	return keyset;
}
Map.prototype.size = function() {
	var count = 0;
	for (var key in this.container) {
		// 跳过object的extend函数
		if (key == 'extend')
			continue;
			
		count++;
	}
	return count;
}
Map.prototype.containsKey = function(key) {
	if(this.container[key] != null)
		return true;
	else
		return false;
}
Map.prototype.toString = function(){
	var str = "";
	for (var i = 0, keys = this.keySet(), len = keys.length; i < len; i++) {
		str = str + keys[i] + "=" + this.container[keys[i]] + ";\n";
	}
	return str;
}

/* JsUtil对象 */
var JsUtil = new Object();
JsUtil.isIE = navigator.userAgent.indexOf("compatible") > -1
		&& navigator.userAgent.indexOf("MSIE") > -1;

JsUtil.setCookie = function(name,value,nDays,path,domain,secure) {
	var cookie = name + "=" + encodeURIComponent(value);
	var expires = "";
	if ( nDays ) {
		var d = new Date();
		d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		cookie += "; expires=" + d.toGMTString();
	}
	if(path) {
		cookie += ";path="+ path;
	}
	if(domain) {
		cookie += ";domain="+domain;
	}
	if(secure) {
		cookie += ";secure";
	}
	document.cookie = cookie;
};

JsUtil.getCookie = function(name) {
	var re = "(?:; )?"+name+"=([^;]*);?";
	var oRE = new RegExp(re);
	
	if(oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	}else{
		return null;
	}
};

JsUtil.removeCookie = function(name) {
	setCookie(name, "", -1);
};

JsUtil.addEventHandler = function (oTarget,sEventType, fnHandler) {
	if (oTarget.addEventListener) {
		oTarget.addEventListener(sEventType, fnHandler, false);
	} else if (oTarget.attachEvent) {
		oTarget.attachEvent("on" + sEventType, fnHandler);
	} else {
		oTarget["on" + sEventType] = fnHandler;
	}
};

JsUtil.removeEventHandler = function (oTarget,sEventType, fnHandler) {
	if (oTarget.removeEventListener) {
		oTarget.removeEventListener(sEventType, fnHandler, false);
	} else if (oTarget.detachEvent) {
		oTarget.detachEvent("on" + sEventType, fnHandler);
	} else {
		oTarget["on" + sEventType] = null;
	}
};

var __sto = setTimeout;
JsUtil.setTimeout = function(callback,timeout,param) {
	var args = Array.prototype.slice.call(arguments,2);
	var _cb = function() {
		callback.apply(null,args);
	};
	var timer = __sto(_cb,timeout);
	return timer;
}
JsUtil.clearTimeout = function(timer) {
	clearTimeout(timer);
}

JsUtil.selectNumForm = function(nFirst, nLast) {
	var choices = nLast - nFirst + 1;
	return Math.floor(Math.random() * choices + nFirst);
};

JsUtil.getAbsolutePos = function (el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

JsUtil.getWindowSize = function() {
	var winWidth = 0;
	var winHeight = 0;
	//获取窗口宽度
	if (window.innerWidth)
		winWidth = window.innerWidth;
    else if ((document.body) && (document.body.clientWidth))
        winWidth = document.body.clientWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		winWidth = document.documentElement.clientWidth;
    //获取窗口高度
    if (window.innerHeight)
        winHeight = window.innerHeight;
    else if ((document.body) && (document.body.clientHeight))
        winHeight = document.body.clientHeight;
    else if (document.documentElement  && document.documentElement.clientHeight)
        winHeight = document.documentElement.clientHeight;
	var p = {width:winWidth, height:winHeight};
	return p;
}

JsUtil.autoFrameHeight = function (name,def) {
	var iframe = document.getElementById(name);
	if(iframe.readyState == "complete")	{
		var height = eval(name).document.body.scrollHeight;
		if(def == undefined)
			def = 480;	//set default height
		if(height<def)
			height = def;
		//height += 20;
		iframe.style.height=height+"px";
	}
};

JsUtil.autoFrameSize = function() {
	var height = document.body.scrollHeight+20;
	var width = document.body.scrollWidth;
	if(window.parent!=undefined) {
		var iframe = window.parent.document.getElementById(window.name);
		if(iframe!=undefined) {
			if(!iframe.style.height)
				iframe.style.height = height;
			else if(parseInt(iframe.style.height) < height)
				iframe.style.height = height;
		}
		if(iframe!=undefined) {
			if(!iframe.style.width)
				iframe.style.width = width;
			else if(parseInt(iframe.style.width) < width)
				iframe.style.width = width;
		}
	}
}

JsUtil.exportExcel = function(table) {
	// Start Excel and get Application object.
	try {
		var oXL = new ActiveXObject("Excel.Application"); 
		// Get a new workbook.
		var oWB = oXL.Workbooks.Add();
		var oSheet = oWB.ActiveSheet;
		var sel=document.body.createTextRange();
  		sel.moveToElementText(table);
  		sel.select();
  		sel.execCommand("Copy");
  		oSheet.Paste();
  		oXL.Visible = true;
		oXL.UserControl = true;
	} catch (e) {
		alert("请确定已安装Excel2000,IE6.0(或更高版本),并且IE安全设置中对ActiveX控件设置为启用！");
	}
};

//过虑字符串中的非法字符
JsUtil.filterXml = function(s) {
	if(s!=null && s!="") {
		s = s.replace(/\&/g,"&amp;");
		s = s.replace(/\</g,"&lt;");
		s = s.replace(/\>/g,"&gt;");
		s = s.replace(/\\/g,"&#92;");
		s = s.replace(/\'/g,"&#039;");
		s = s.replace(/\"/g,"&#034;");
	}
	return s;
};

//同上过程相反
JsUtil.unfilterXml = function(s) {
	if(s!=null && s!="") {
		s = s.replace(/&amp;/g,"&");
		s = s.replace(/&lt;/g,"<");
		s = s.replace(/&gt;/g,">");
		s = s.replace(/&#92;/g,"\\");
		s = s.replace(/&#039;/g,"\'");
		s = s.replace(/&#034;/g,"\"");
	}
	return s;
};

//获得时间差值
JsUtil.getPeriodTime = function(time1,time2) {
	var parseDate = function(s) {
		var re = /^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/;
		if (s=="" || !re.test(s)) {
			return null;
		}
		var year = parseInt(s.substring(0,4),10);
		var month = parseInt(s.substring(5,7),10);
		var day = parseInt(s.substring(8,10),10);
		var hour = parseInt(s.substring(11,13),10);
		var min = parseInt(s.substring(14,16),10);
		var sec = parseInt(s.substring(17),10);
		return Date.UTC(year,month,day,hour,min,sec);
	}
	var date1 = parseDate(time1);
	var date2 = parseDate(time2);
	var s = "";
	if (date1!=null && date2!=null) {
		var sub1 = Math.abs(date2 - date1);
		var day = Math.floor(sub1/(1000*60*60*24));
		var hour = Math.floor(sub1/(1000*60*60) % 24);
		var min1 = Math.floor(sub1/(1000*60) % 60);
		var sec = Math.floor(sub1/1000 % 60);
		if (day >= 1) {
			s = day + "天";
		}
		if (hour >= 1) {
			s += hour + "小时";
		}
		if (min1 >= 1) {
			s += min1 + "分";
		}
		if (sec >= 1) {
			s += sec + "秒";
		}
	}
	return s;
}

//打开加载提示
JsUtil.showLoadingBox = function(button,left,top) {
	var loadDiv = $("loadingbox");
	if(loadDiv!=null) {
		loadDiv.style.display = "block";
	}else{
		loadDiv = document.createElement("div");
		loadDiv.id = "loadingbox";
		loadDiv.className = "loading";
		loadDiv.appendChild(document.createTextNode("加载中，请稍等"));
		if(left!=null && top!=null) {
			loadDiv.style.left = left;
			loadDiv.style.top = top;
		}
		document.body.appendChild(loadDiv);
	}
	if(button!=null) {
		button.disabled = true;
	}
};

JsUtil.hideLoadingBox = function(button) {
	var loadDiv = $("loadingbox");
	if(loadDiv!=null)
		loadDiv.style.display = "none";
	if(button!=null) {
		button.disabled = false;
	}
}

//缓存对象
JsUtil.setObject = function(element,obj) {
	element._obj = obj;
}
JsUtil.getObject = function(element) {
	return element._obj;
}

//设置boolean型的字段值
JsUtil.setBooleanValue = function(checked,input) {
	if(checked)
		$(input).value = "true";
	else
		$(input).value = "false";
}

//获得当前地址
JsUtil.getLocationURL = function() {
	var path = window.location.pathname;
	var query = window.location.search;
	if(query != "")
		query = query.replace(/\&/g,"^");
	return path+query;
}

JsUtil.getParameter = function (param) { 
	var query = window.location.search; 
	var iLen = param.length; 
	var iStart = query.indexOf(param); 
	if (iStart == -1) 
		return ""; 
	iStart += iLen + 1; 
	var iEnd = query.indexOf("&", iStart); 
	if (iEnd == -1) 
		return query.substring(iStart); 
	return query.substring(iStart, iEnd); 
}

JsUtil.parseXml = function(s) {
	var XmlDom = function() {
		if(window.ActiveXObject) {
			var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
								 "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument","Microsoft.XmlDom"];
			for (var i=0; i < arrSignatures.length; i++) {
				try {
					var oXmlDom = new ActiveXObject(arrSignatures[i]);
					return oXmlDom;
				} catch (oError) {
					//ignore
				}
			}
			throw new Error("MSXML is not installed on your system."); 
		}else{
			var oParser = new DOMParser();
			var oXmlDom = oParser.parseFromString(s,"text/xml");
			return oXmlDom;
		}
	};
	var obj = new XmlDom();
	if (JsUtil.isIE) {
		obj.async = false;
		obj.loadXML(s);
		obj.onreadystatechange = function() {
			if(obj.readyState == 4) {
				return obj;
			}
		}
	} else {
		return obj;
	}
	return obj;
}

JsUtil.parseJson = function(s) {
	var obj = null;
	if(s) {
		s = "var _json="+s;
		eval(s);
		obj = _json;
	}
	return obj;
}

function XmlDomParser(doc) {
	this.doc = doc;
}
XmlDomParser.prototype._parseObject =  function(e) {
	if(e == null)
		return null;
	var obj = new Object();
	var attributes = e.attributes;
	var nodes = e.childNodes;
	if (attributes.length >0) {
		for(var i=0;i<attributes.length;i++) {
			var attr = attributes.item(i);
			obj[attr.nodeName] = attr.nodeValue;
		}
	} else {
		for (var i=0;i<nodes.length;i++) {
			var temp = nodes[i];
			obj[temp.nodeName] = temp.text;
		}
	}
	obj.text = e.text;
	return obj;
}
XmlDomParser.prototype.getText = function(xpath) {
	var e = this.doc.selectSingleNode(xpath);
	return e!=null ? e.text:null;
}
XmlDomParser.prototype.getObject = function(xpath) {
	var e = this.doc.selectSingleNode(xpath);
	return this._parseObject(e);
}
XmlDomParser.prototype.getArray = function(xpath) {
	var tempArray = this.doc.selectNodes(xpath);
	var array = new Array(tempArray.length);
	for(var i=0;i<tempArray.length;i++) {
		var obj = this._parseObject(tempArray[i]);
		array[i] = obj;
	}
	return array;
}

//fix firefox
if (!JsUtil.isIE) {
	Element.prototype.selectNodes = function(xpath) {
		var evaluator = new XPathEvaluator();
		var result = evaluator.evaluate(xpath,this,null,
										XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
		var nodes = new Array();
		if (result != null) {
			var element = result.iterateNext();
			while(element) {
				nodes.push(element);
				element = result.iterateNext();
			}
		}
		return nodes;
	}
	Element.prototype.selectSingleNode = function(xpath) {
		var evaluator = new XPathEvaluator();
		var result = evaluator.evaluate(xpath,this,null,
										XPathResult.FIRST_ORDERED_NODE_TYPE,null);
		if (result !=null) {
			return result.singleNodeValue;
		} else {
			return null;
		}
	}
	Element.prototype.__defineGetter__("text",function(){ return this.textContent; });
}

/*
Ajax函数
*/
function AjaxRequest(p) {
	this.url = null;
	this.method = null;
	this.parameters = null;
	this.asynchronous = true;
	this.button = null;
	this.onCreate = null;
	this.onComplete = null;
	this.request = null;
	this.showLoading = true;
	this.showError = false;
	//初始化
	this.init(p);
}
AjaxRequest.prototype.init = function(p) {
	this.url = p.url ? p.url : "";
	this.method = p.method ? p.method : "get";
	this.parameters = p.parameters ? p.parameters : "";
	this.asynchronous = p.asynchronous==undefined ? true : p.asynchronous;
	this.button = p.button ? p.button : null;
	this.onCreate = p.onCreate ? p.onCreate : function(){};
	this.onComplete = p.onComplete ? p.onComplete : function(){};
	this.showLoading = p.showLoading==undefined ?  true : p.showLoading;
	this.showError = p.showError==undefined ? false : p.showError;
	this.request = this.createXmlRequest();
}
AjaxRequest.prototype.createXmlRequest = function() {
	var req = null;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	}else if(window.ActiveXObject) {
		var array = ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
		for(var i=0;i<array.length;i++) {
			try {
				req = new ActiveXObject(array[i]);
				break;
			}catch(e){
				//ignore
			}
		}
	}else{
		alert("您的浏览器目前不支持javascript请求!");
	}
	return req;
}
AjaxRequest.prototype.addParameter = function(name,value) {
//	var s = name+"="+value;
//	if("get" == this.method)
	var s = encodeURIComponent(name)+"="+encodeURIComponent(value);
	if(this.parameters.length >0)
		this.parameters += "&";
	this.parameters += s;
}
AjaxRequest.prototype.send = function() {
	if("get" == this.method) {
		var obj = this;
		var req = this.request;
		if(this.parameters != "")
			this.url = this.url+"?"+this.parameters;
		req.open("get",this.url,this.asynchronous);
		req.onreadystatechange = function() {
			if(req.readyState == 4) {
				if(req.status==200 || req.status==0) {
					obj.onComplete(req);
				}else if(req.status==404){
					if(obj.showError)
					alert("您请求的地址不存在!"+req.status);
				}else if(req.status==500){
					if(obj.showError)
					alert("程序发生了错误!"+req.status);
				}else{
					if(obj.showError)
					alert("error status:"+req.status);
				}
				if(obj.showLoading)
					JsUtil.hideLoadingBox(obj.button);
			}
		}
		this.onCreate();
		if(this.showLoading)
			JsUtil.showLoadingBox(this.button);
		req.send(null);
	} else {
		var obj = this;
		var req = this.request;
		req.open("post",this.url,this.asynchronous);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.onreadystatechange = function() {
			if(req.readyState == 4) {
				if(req.status==200 || req.status==0) {
					obj.onComplete(req);
				}else if(req.status==404){
					if(obj.showError)
					alert("您请求的地址不存在!"+req.status);
				}else if(req.status==500){
					if(obj.showError)
					alert("程序发生了错误!"+req.status);
				}else{
					if(obj.showError)
					alert("error status:"+req.status);
				}
				if(obj.showLoading)
					JsUtil.hideLoadingBox(obj.button);
			}
		}
		this.onCreate();
		if(this.showLoading)
			JsUtil.showLoadingBox(this.button);
		req.send(this.parameters);
	}
}

JsUtil.createXMLHttpRequest = function(param) {
	return new AjaxRequest(param);
}

//input框变颜色
var oldInputBorderColor = "#7b9ebd";
var focusInputBorderColor = "#8dcf23";
function alterInputBorderColor() {
	var input = window.event.srcElement;
	var color = input.currentStyle.borderColor.toLowerCase();
	if(color == focusInputBorderColor) {
		input.style.borderColor = oldInputBorderColor;
	} else {
		input.style.borderColor = focusInputBorderColor;
	}
}
function setupInputBorderAlter() {
	var forms = document.forms;
	if(forms!=null && forms.length>0) {
		for(var j=0;j<forms.length;j++) {
			var f = forms[j];
			for(var i=0;i<f.elements.length;i++) {
				var E = f.elements[i];
				if(
					(E.nodeName=="INPUT" && E.type=="text" && !E.disabled && !E.readOnly)
						|| (E.nodeName=="INPUT" && E.type=="file" && !E.disabled && !E.readOnly)
						|| (E.nodeName=="INPUT" && E.type=="password" && !E.disabled && !E.readOnly)
						|| (E.nodeName=="TEXTAREA" && !E.disabled && !E.readOnly)
				) {
					JsUtil.addEventHandler(E,"focus",alterInputBorderColor);
					JsUtil.addEventHandler(E,"blur",alterInputBorderColor);
				}
			}
		}
	}
}
JsUtil.addEventHandler(window,"load",setupInputBorderAlter);

JsUtil.ajaxForward = function(tempURL,boxId) {
	var freshBoxContent = function(req) {
		var text = req.responseText.trim();
		$(boxId).innerHTML = text;
	}
	var param = {
		url : tempURL,
		method : "get",
		onComplete : freshBoxContent
	};
	var request = new AjaxRequest(param);
	request.send();
}

JsUtil.openURL = function(field,ctxpath) {
	if($(field)==null || $(field).value=="")
		return;
	var url = $(field).value;
	if (ctxpath!=undefined && url.charAt(0)=='/')
		url = ctxpath + url;
	if(url.indexOf("http")==0) {
		window.open(url);
	} else if (url.indexOf("www")==0) {
		url = "http://"+url;
		window.open(url);
	} else {
		openWin(url);
	}
}

JsUtil.getRadioValue = function(radio) {
	var value = "";
	if(radio == undefined)
		return "";
	if(typeof radio.length != "undefined") {
		for(var i=0;i<radio.length;i++) {
			if(radio[i].checked && !radio[i].disabled) {
				value = radio[i].value;
				break;
			}
		}
	}else{
		value = radio.value;
	}
	return value;
}

JsUtil.getCheckBoxValue = function(cb) {
	var value = "";
	if (cb == null)
		return "";
	else if (cb.length==undefined && cb.checked) {
		value = cb.value;
	} else {
		for(var i=0;i<cb.length;i++) {
			var temp = cb[i];
			if(temp.checked) {
				if(value == "")
					value = temp.value;
				else
					value += ","+temp.value;
			}
		}
	}
	return value;
}

JsUtil.parseContextPath = function() {
	var jsFile = "/ui/js/JsUtil.js";
	var ctxpath = "";
	var tagURL = "";
	var pageURL = window.location.pathname;
	pageURL = pageURL.substring(0,pageURL.lastIndexOf("/"));
	var tag = document.getElementById("JsUtil");
	if (tag == null) {
		var array = document.getElementsByTagName("script");
		for(var i=0;i<array.length;i++) {
			var src = array[i].src;
			if (src!="" && src.indexOf("JsUtil.js")!=-1) {
				tag = array[i];
				break;
			}
		}
	}
	if (tag != null) {
		var tagSrc = tag.src;
		if (tagSrc.indexOf("/") == 0) {
			tagURL = tagSrc;
		} else {
			if (tagSrc.indexOf("JsUtil.js") == 0) {
				tagURL = pageURL + "/JsUtil.js";
			} else {
				while (tagSrc.indexOf("../") != -1) {
					tagSrc = tagSrc.substring(0,tagSrc.lastIndexOf("../"));
					pageURL = pageURL.substring(0,pageURL.lastIndexOf("/"));
				}
				tagURL = pageURL + "/JsUtil.js";
			}
		}
		//alert(tagURL);
		ctxpath = tagURL.substring(0,tagURL.indexOf(jsFile));
	}
	//alert(ctxpath);
	document.ctxpath = ctxpath;
	return ctxpath;
}
JsUtil.parseContextPath();

JsUtil.cleanXML = function(html){
	var re = new RegExp("<\\/?[a-z][^>]*>","ig");
	var s = html.replace(re,"");
	return s;
}

JsUtil.findParent = function(node,q) {
	var parent = null;
	var p = node.parentNode;
	while(p != null) {
		if (q == null || q == "") {
			parent = p;
			break;
		} else {
			var nodeName = "";
			var className = "";
			if (q.indexOf(".")!=-1) {
				nodeName = q.substring(0,q.indexOf("."));
				className = q.substring(q.indexOf(".")+1);
			} else {
				nodeName = q;
			}
			if (nodeName != "" && className != "") {
				if (p.className == className && p.nodeName.toLowerCase() == nodeName) {
					parent = p;
					break;
				} else {
					p = p.parentNode;
				}
			} else if (nodeName != "" && className == "") {
				if (p.nodeName.toLowerCase() == nodeName) {
					parent = p;
					break;
				} else {
					p = p.parentNode;
				}
			} else if (nodeName == "" && className != "") {
				if (p.className == className) {
					parent = p;
					break;
				} else {
					p = p.parentNode;
				}
			}
		}
	}
	return parent;
}

JsUtil.findChilds = function(node,q) {
	var childs = new Array();
	var nodeName = "";
	var className = "";
	if (q == null || q == "") {
		for (var i=0;i<node.childNodes.length;i++) {
			var temp = node.childNodes[i];
			childs.push(temp);
		}
	} else {
		if (q.indexOf(".")!=-1) {
			nodeName = q.substring(0,q.indexOf("."));
			className = q.substring(q.indexOf(".")+1);
		} else {
			nodeName = q;
		}
		for (var i=0;i<node.childNodes.length;i++) {
			var temp = node.childNodes[i];
			if (nodeName != "" && temp.nodeName.toLowerCase()!=nodeName)
				continue;
			if (className != "" && temp.className != className)
				continue;
			childs.push(temp);
		}
	}
	return childs;
}

JsUtil.getElementsByClassName = function(className, parentElement) {
	var children = ($(parentElement) || document.body).getElementsByTagName('*');
    var elements = [], child;
    for (var i = 0, length = children.length; i < length; i++) {
      child = children[i];
      if (child.className == className)
        elements.push(child);
    }
    return elements;
}

function TitleBlink(msg) {
	this.msg = msg;
	this.title = window.top.document.title;
	this.speed = 1;
	this.timer = null;
	this.blank = "　　　　　　";
}
TitleBlink.prototype.start = function() {
	var count = 1;
	var func = function() {
		if (count % 2 == 0)
			window.top.document.title = this.msg;
		else
			window.top.document.title = this.blank;
		count ++;
	}
	this.timer = setInterval(func.bind(this),1000*this.speed);
	JsUtil.addEventHandler(document.body,"click",this.stop.bind(this));
}
TitleBlink.prototype.stop = function() {
	clearInterval(this.timer);
	window.top.document.title = this.title;
	JsUtil.removeEventHandler(document.body,"click",this.stop.bind(this));
}

function URLParser() {
	this.path = window.location.pathname;
	this.params = this.parse();
}
URLParser.prototype.setParameter = function(name,value) {
	this.params.put(name,encodeURIComponent(value));
}
URLParser.prototype.getParameter = function(name) {
	return this.params.get(name);
}
URLParser.prototype.parse = function() {
	var query = window.location.search;
	var map = new Map();
	var re = /[\?|\&][\w]+=([^\&])*/g;
	var array = query.match(re);
	for (var i=0;i<array.length;i++) {
		var index = array[i].indexOf("=");
		var name = array[i].substring(1,index);
		var value = array[i].substring(index+1);
		map.put(name,value);
	}
	return map;
}
URLParser.prototype.toString = function() {
	var sb = new StringBuffer();
	sb.append(this.path);
	for (var i = 0, keys = this.params.keySet(), len = keys.length; i < len; i++) {
		if (i == 0)
			sb.append("?"+keys[i]+ "=" +this.params.get(keys[i]));
		else
			sb.append("&"+keys[i]+ "=" +this.params.get(keys[i]));
	}
	return sb.toString();
}